<template>
	<view>
		<tn-nav-bar :isBack='true' :backTitle='" "' bottomShadow :alpha="alpha">登录</tn-nav-bar>
		<image src="/static/product/topbg.png" class="topbg" mode=""></image>
		<!-- <view > -->
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}" class="con">
			<view class="" style="margin-top: 140rpx;">

			</view>
			<image src="/static/logo.png" class="con__logo" mode=""></image>
			<view class="con__text">
				飞象云游
			</view>
			<view class="con__btn">
				<tn-button @getphonenumber="getphonenumber" :openType="!isgx?'default':'getPhoneNumber'"
					fontColor="#FFFFFF" shape='round' width='650rpx' height='64rpx' :fontSize='24'
					backgroundColor="tn-bg-lv" @click="!isgx&&msg('请阅读并且同意用户服务协议、隐私政策')">一键登录</tn-button>

				<view class="" style="height: 50rpx;width: 650rpx;">

				</view>
				<!-- <u-button text="其它手机号登录" @click="clickqt" plain  :customStyle="{height:'80rpx',}"></u-button> -->
			</view>
			<view class="tn-flex tn-flex-xy-center">
				<view class="" @click="isgx=!isgx">
					<!-- <u-icon name="/static/my/yx.png" size="40rpx" v-if="isgx"></u-icon> -->
					<!-- 	<image src="/static/product/gou.png" style="width: 40rpx;height: 40rpx;" mode="" v-if="isgx">
					</image>
					<image src="/static/product/gou.png" style="width: 40rpx;height: 40rpx;" mode="" v-else></image> -->
					<!-- <u-icon name="" size="40rpx" v-else></u-icon> -->
					<u-checkbox :checked="isgx" @change="e=>isgx=e"></u-checkbox>
				</view>
				<view class="con__text">
					我已阅读并同意 <text style="color: #0384fc;">
						<text @click="to('/pages/my/xiyi?name=userSerive&title=飞象云游服务条款')">用户服务协议</text>、
						<text @click="to('/pages/my/xiyi?name=secret&title=飞象云游隐私政策')">隐私政策</text></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				isgx: false,
				alpha: true
			};
		},
		methods: {
			getphonenumber(e) {
				let _this = this
				// console.log(_this.$store.commit('getuserifo'))
				console.log(e)
				uni.login({
					"provider": "weixin",
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success: function(loginRes) {
						console.log(loginRes)
						user.getopenid({
							code: loginRes.code
						}).then(res1 => {
							// let openid = res.data.data.openid
							// console.log(res1)
							user.getWechatPhone({
								session_key: res1.data.data.session_key,
								iv: e.iv,
								encryptedData: e.encryptedData,
								openid: res1.data.data.openid,
								salt: _this.$store.state.vuex_salt
							}).then(res => {
								if (res.data.code == 1) {
									_this.$tn.vuex('vuex_token', res.data.data.token)
									_this.$tn.vuex('vuex_salt', '')
									user.userinex().then(res1 => {
										if (res.data.code == 1) {
											_this.$tn.vuex('vuex_userinfo', res1.data
												.data)
											// 判断头像是否默认
											if (_this.$store.state.vuex_userinfo.avatar
												.includes(
													'data:')) { //跳转修改页面
												uni.redirectTo({
													url: '/pages/profit/info'
												})
											} else {
												uni.navigateBack()
											}
										}
									})


								} else {
									uni.showToast({
										title: '登录失败，请重新登录',
										icon: 'none'
									})
								}
							})
						})
					}
				})
			},
			nogx() {
				if (!this.isgx) {
					uni.showToast({
						title: '请阅读并勾选用户协议',
						icon: 'none'
					})
					return
				}
			},
			clickqt() {
				if (!this.isgx) {
					uni.showToast({
						title: '请阅读并勾选用户协议',
						icon: 'none'
					})
					return
				}
				this.to('/pages/my/codelogin')
			}
		}
	}
</script>

<style lang="scss">
	.con {
		padding: 0 50rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		&__logo {
			width: 160rpx;
			height: 160rpx;
			border-radius: 40rpx;
			margin-bottom: 40rpx;
		}

		&__btn {
			width: 650rpx;
			margin-bottom: 100rpx;
			margin-top: 100rpx;
		}

		&__text {
			font-size: 24rpx;
			margin-left: 10rpx;
		}
	}
</style>